home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt32s2.arc / PIBASYN2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-07  |  29.8 KB  |  627 lines

  1. (*----------------------------------------------------------------------*)
  2. (*      Async_Carrier_Detect --- Check for modem carrier detect         *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. FUNCTION Async_Carrier_Detect : BOOLEAN;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Function:   Async_Carrier_Detect                                 *)
  10. (*                                                                      *)
  11. (*     Purpose:    Looks for modem carrier detect                       *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Flag := Async_Carrier_Detect : BOOLEAN;                       *)
  16. (*                                                                      *)
  17. (*           Flag is set TRUE if carrier detected, else FALSE.          *)
  18. (*                                                                      *)
  19. (*     Calls:  None                                                     *)
  20. (*                                                                      *)
  21. (*----------------------------------------------------------------------*)
  22.  
  23. BEGIN (* Async_Carrier_Detect *)
  24.  
  25.    Async_Carrier_Detect := ODD( Port[ UART_MSR + Async_Base ] SHR 7 );
  26.  
  27. END   (* Async_Carrier_Detect *);
  28.  
  29. (*----------------------------------------------------------------------*)
  30. (*      Async_Carrier_Drop --- Check for modem carrier drop/timeout     *)
  31. (*----------------------------------------------------------------------*)
  32.  
  33. FUNCTION Async_Carrier_Drop : BOOLEAN;
  34.  
  35. (*----------------------------------------------------------------------*)
  36. (*                                                                      *)
  37. (*     Function:   Async_Carrier_Drop                                   *)
  38. (*                                                                      *)
  39. (*     Purpose:    Looks for modem carrier drop/timeout                 *)
  40. (*                                                                      *)
  41. (*     Calling Sequence:                                                *)
  42. (*                                                                      *)
  43. (*        Flag := Async_Carrier_Drop : BOOLEAN;                         *)
  44. (*                                                                      *)
  45. (*           Flag is set TRUE if carrier dropped, else FALSE.           *)
  46. (*                                                                      *)
  47. (*     Calls:  None                                                     *)
  48. (*                                                                      *)
  49. (*----------------------------------------------------------------------*)
  50.  
  51. BEGIN (* Async_Carrier_Drop *)
  52.  
  53.    Async_Carrier_Drop := NOT ODD( Port[ UART_MSR + Async_Base ] SHR 7 );
  54.  
  55. END   (* Async_Carrier_Drop *);
  56.  
  57. (*----------------------------------------------------------------------*)
  58. (*      Async_Term_Ready --- Set terminal ready status                  *)
  59. (*----------------------------------------------------------------------*)
  60.  
  61. PROCEDURE Async_Term_Ready( Ready_Status : BOOLEAN );
  62.  
  63. (*----------------------------------------------------------------------*)
  64. (*                                                                      *)
  65. (*     Procedure:  Async_Term_Ready                                     *)
  66. (*                                                                      *)
  67. (*     Purpose:    Sets terminal ready status                           *)
  68. (*                                                                      *)
  69. (*     Calling Sequence:                                                *)
  70. (*                                                                      *)
  71. (*        Async_Term_Ready( Ready_Status : BOOLEAN );                   *)
  72. (*                                                                      *)
  73. (*           Ready_Status --- Set TRUE to set terminal ready on,        *)
  74. (*                            Set FALSE to set terminal ready off.      *)
  75. (*                                                                      *)
  76. (*     Calls:  None                                                     *)
  77. (*                                                                      *)
  78. (*----------------------------------------------------------------------*)
  79.  
  80. VAR
  81.    Mcr_Value: BYTE;
  82.  
  83. BEGIN (* Async_Term_Ready *)
  84.  
  85.    Mcr_Value := Port[ UART_MCR + Async_Base ];
  86.  
  87.    IF ODD( Mcr_Value ) THEN Mcr_Value := Mcr_Value - 1;
  88.  
  89.    IF Ready_Status THEN Mcr_Value := Mcr_Value + 1;
  90.  
  91.    Port[ UART_MCR + Async_Base ] := Mcr_Value;
  92.  
  93. END   (* Async_Term_Ready *);
  94.  
  95. (*----------------------------------------------------------------------*)
  96. (*          Async_Buffer_Check --- Check if character in buffer         *)
  97. (*----------------------------------------------------------------------*)
  98.  
  99. FUNCTION Async_Buffer_Check : BOOLEAN;
  100.  
  101. (*----------------------------------------------------------------------*)
  102. (*                                                                      *)
  103. (*     Function:   Async_Buffer_Check                                   *)
  104. (*                                                                      *)
  105. (*     Purpose:    Check if character in buffer                         *)
  106. (*                                                                      *)
  107. (*     Calling Sequence:                                                *)
  108. (*                                                                      *)
  109. (*        Flag := Async_Buffer_Check : BOOLEAN;                         *)
  110. (*                                                                      *)
  111. (*           Flag returned TRUE if character received in buffer,        *)
  112. (*           Flag returned FALSE if no character received.              *)
  113. (*                                                                      *)
  114. (*     Calls:  None                                                     *)
  115. (*                                                                      *)
  116. (*     Remarks:                                                         *)
  117. (*                                                                      *)
  118. (*       This routine only checks if a character has been received      *)
  119. (*       and thus can be read; it does NOT return the character.        *)
  120. (*       Use Async_Receive to read the character.                       *)
  121. (*                                                                      *)
  122. (*----------------------------------------------------------------------*)
  123.  
  124. BEGIN   (* Async_Buffer_Check *)
  125.  
  126.    Async_Buffer_Check := ( Async_Buffer_Head <> Async_Buffer_Tail );
  127.  
  128. END     (* Async_Buffer_Check *);
  129.  
  130. (*----------------------------------------------------------------------*)
  131. (*          Async_Receive --- Return character from buffer              *)
  132. (*----------------------------------------------------------------------*)
  133.  
  134. FUNCTION Async_Receive( VAR C : Char ) : BOOLEAN;
  135.  
  136. (*----------------------------------------------------------------------*)
  137. (*                                                                      *)
  138. (*     Function:   Async_Receive                                        *)
  139. (*                                                                      *)
  140. (*     Purpose:    Retrieve character (if any) from buffer              *)
  141. (*                                                                      *)
  142. (*     Calling Sequence:                                                *)
  143. (*                                                                      *)
  144. (*        Flag := Async_Receive( VAR C: Char ) : BOOLEAN;               *)
  145. (*                                                                      *)
  146. (*           C --- character (if any) retrieved from buffer;            *)
  147. (*                 set to CHR(0) if no character available.             *)
  148. (*                                                                      *)
  149. (*           Flag returned TRUE if character retrieved from buffer,     *)
  150. (*           Flag returned FALSE if no character retrieved.             *)
  151. (*                                                                      *)
  152. (*     Calls:  None                                                     *)
  153. (*                                                                      *)
  154. (*----------------------------------------------------------------------*)
  155.  
  156. BEGIN   (* Async_Receive *)
  157.  
  158.    IF Async_Buffer_Head = Async_Buffer_Tail THEN
  159.       BEGIN (* No character to retrieve *)
  160.  
  161.          Async_Receive := FALSE;
  162.          C             := CHR( 0 );
  163.  
  164.       END   (* No character available   *)
  165.  
  166.    ELSE
  167.       BEGIN (* Character available *)
  168.  
  169.                    (* Turn off interrupts *)
  170.  
  171.          INLINE( $FA );       (* CLI --- Turn off interrupts *)
  172.  
  173.                    (* Get character from buffer *)
  174.  
  175.          C := Async_Buffer[ Async_Buffer_Tail ];
  176.  
  177.                    (* Increment buffer pointer.   IF past *)
  178.                    (* end of buffer, reset to beginning.  *)
  179.  
  180.          Async_Buffer_Tail := Async_Buffer_Tail + 1;
  181.  
  182.          IF Async_Buffer_Tail > Async_Buffer_Max THEN
  183.             Async_Buffer_Tail := 0;
  184.  
  185.                    (* Decrement buffer use count *)
  186.  
  187.          Async_Buffer_Used  := Async_Buffer_Used - 1;
  188.  
  189.                    (* Turn on interrupts *)
  190.  
  191.          INLINE( $FB );       (* STI --- Turn on interrupts *)
  192.  
  193.                    (* Indicate character successfully retrieved *)
  194.  
  195.          Async_Receive := TRUE;
  196.  
  197.       END   (* Character available *);
  198.  
  199. END   (* Async_Receive *);
  200.  
  201. (*----------------------------------------------------------------------*)
  202. (*   Async_Receive_With_TimeOut --- Return char. from buffer with delay *)
  203. (*----------------------------------------------------------------------*)
  204.  
  205. PROCEDURE Async_Receive_With_Timeout( Secs : INTEGER; VAR C : INTEGER );
  206.  
  207. (*----------------------------------------------------------------------*)
  208. (*                                                                      *)
  209. (*     Procedure:  Async_Receive_With_Timeout                           *)
  210. (*                                                                      *)
  211. (*     Purpose:    Retrieve character as integer from buffer,           *)
  212. (*                 or return TimeOut if specified delay period          *)
  213. (*                 expires.                                             *)
  214. (*                                                                      *)
  215. (*     Calling Sequence:                                                *)
  216. (*                                                                      *)
  217. (*        Async_Receive_With_Timeout( Secs: INTEGER; VAR C: INTEGER );  *)
  218. (*                                                                      *)
  219. (*           Secs ---  Timeout period in seconds                        *)
  220. (*           C     --- ORD(character) (if any) retrieved from buffer;   *)
  221. (*                     set to TimeOut if no character found before      *)
  222. (*                     delay period expires.                            *)
  223. (*                                                                      *)
  224. (*     Calls:  Async_Receive                                            *)
  225. (*             TimeOfDay                                                *)
  226. (*                                                                      *)
  227. (*     WATCH OUT!  THIS ROUTINE RETURNS AN INTEGER, NOT A CHARACTER!!!  *)
  228. (*                                                                      *)
  229. (*----------------------------------------------------------------------*)
  230.  
  231. VAR
  232.    Ch           : CHAR;
  233.    Time_Limit   : REAL;
  234.    B            : BOOLEAN;
  235.  
  236. BEGIN (* Async_Receive_With_Timeout *)
  237.  
  238.    IF Async_Buffer_Head <> Async_Buffer_Tail THEN
  239.       BEGIN
  240.          B := Async_Receive( Ch );
  241.          C := ORD( Ch );
  242.       END
  243.    ELSE
  244.       BEGIN
  245.                                    (* Convert time to milliseconds *)
  246.  
  247.          Time_Limit := Secs * 1000.0;
  248.  
  249.          WHILE ( Async_Buffer_Head = Async_Buffer_Tail ) AND
  250.                ( Time_Limit > 0.0 ) DO
  251.             BEGIN
  252.                Delay( 1 );
  253.                Time_Limit := Time_Limit - 1.0;
  254.             END;
  255.  
  256.          IF ( Async_Buffer_Head <> Async_Buffer_Tail ) AND
  257.             ( Time_Limit > 0.0 ) THEN
  258.             BEGIN
  259.                B := Async_Receive( Ch );
  260.                C := ORD( Ch );
  261.             END
  262.          ELSE
  263.             C := TimeOut;
  264.  
  265.       END;
  266.  
  267. END   (* Async_Receive_With_Timeout *);
  268.  
  269. (*----------------------------------------------------------------------*)
  270. (*            Async_Ring_Detect --- Check for phone ringing             *)
  271. (*----------------------------------------------------------------------*)
  272.  
  273. FUNCTION Async_Ring_Detect : BOOLEAN;
  274.  
  275. (*----------------------------------------------------------------------*)
  276. (*                                                                      *)
  277. (*     Function:   Async_Ring_Detect                                    *)
  278. (*                                                                      *)
  279. (*     Purpose:    Looks for phone ringing                              *)
  280. (*                                                                      *)
  281. (*     Calling Sequence:                                                *)
  282. (*                                                                      *)
  283. (*        Flag := Async_Ring_Detect : BOOLEAN;                          *)
  284. (*                                                                      *)
  285. (*           Flag is set TRUE if ringing detected, else FALSE.          *)
  286. (*                                                                      *)
  287. (*     Calls:  None                                                     *)
  288. (*                                                                      *)
  289. (*----------------------------------------------------------------------*)
  290.  
  291. BEGIN (* Async_Ring_Detect *)
  292.  
  293.    Async_Ring_Detect := ODD( Port[ UART_MSR + Async_Base ] SHR 6 );
  294.  
  295. END   (* Async_Ring_Detect *);
  296.  
  297. (*----------------------------------------------------------------------*)
  298. (*          Async_Send --- Send character over communications port      *)
  299. (*----------------------------------------------------------------------*)
  300.  
  301. PROCEDURE Async_Send( C : Char );
  302.  
  303. (*----------------------------------------------------------------------*)
  304. (*                                                                      *)
  305. (*     Procedure:  Async_Send                                           *)
  306. (*                                                                      *)
  307. (*     Purpose:    Sends character out over communications port         *)
  308. (*                                                                      *)
  309. (*     Calling Sequence:                                                *)
  310. (*                                                                      *)
  311. (*        Async_Send( C : Char );                                       *)
  312. (*                                                                      *)
  313. (*           C --- Character to send                                    *)
  314. (*                                                                      *)
  315. (*     Calls:  None                                                     *)
  316. (*                                                                      *)
  317. (*----------------------------------------------------------------------*)
  318.  
  319. VAR
  320.    TimeOut : INTEGER;
  321.  
  322. BEGIN   (* Async_Send *)
  323.  
  324.                    (* Turn on OUT2, DTR, and RTS *)
  325.  
  326.    Port[UART_MCR + Async_Base] := $0B;
  327.  
  328.                    (* Wait for DSR using Busy Wait *)
  329.  
  330.    IF Async_Do_DSR THEN
  331.       BEGIN
  332.          TimeOut := 32767;
  333.          WHILE ( ( Port[UART_MSR + Async_Base] AND $20 ) = 0 ) AND
  334.                  ( TimeOut > -32767 ) DO
  335.             TimeOut := TimeOut - 1;
  336.       END;
  337.  
  338.                    (* Wait for CTS using Busy Wait *)
  339.  
  340.    IF Async_Do_CTS THEN
  341.       BEGIN
  342.          TimeOut := 32767;
  343.          WHILE ( ( Port[UART_MSR + Async_Base] AND $10 ) = 0 ) AND
  344.                  ( TimeOut > -32767 ) DO
  345.             TimeOut := TimeOut - 1;
  346.       END;
  347.  
  348.                    (* Wait for Transmit Hold Register Empty (THRE) *)
  349.  
  350.    IF TimeOut > -32767 THEN
  351.       TimeOut := 32767;
  352.  
  353.    WHILE ( ( Port[UART_LSR + Async_Base] AND $20 ) = 0 ) AND
  354.            ( TimeOut > -32767 ) DO
  355.       TimeOut := TimeOut - 1;
  356.  
  357.                    (* Send the character when port clear *)
  358.  
  359.    INLINE($FA);                    (* CLI --- disable interrupts *)
  360.  
  361.    Port[UART_THR + Async_Base] := ORD( C );
  362.  
  363.    INLINE($FB);                    (* STI --- enable interrupts *)
  364.  
  365. END    (* Async_Send *);
  366.  
  367. (*----------------------------------------------------------------------*)
  368. (*          Async_Send_Break --- Send break (attention) signal          *)
  369. (*----------------------------------------------------------------------*)
  370.  
  371. PROCEDURE Async_Send_Break;
  372.  
  373. (*----------------------------------------------------------------------*)
  374. (*                                                                      *)
  375. (*     Procedure:  Async_Send_Break                                     *)
  376. (*                                                                      *)
  377. (*     Purpose:    Sends break signal over communications port          *)
  378. (*                                                                      *)
  379. (*     Calling Sequence:                                                *)
  380. (*                                                                      *)
  381. (*        Async_Send_Break;                                             *)
  382. (*                                                                      *)
  383. (*     Calls:  None                                                     *)
  384. (*                                                                      *)
  385. (*----------------------------------------------------------------------*)
  386.  
  387. VAR
  388.    Old_Lcr   : BYTE;
  389.    Break_Lcr : BYTE;
  390.  
  391. BEGIN (* Async_Send_Break *)
  392.  
  393.    Old_Lcr   := Port[ UART_LCR + Async_Base ];
  394.    Break_Lcr := Old_Lcr;
  395.  
  396.    IF Break_Lcr >  127 THEN Break_Lcr := Break_Lcr - 128;
  397.    IF Break_Lcr <=  63 THEN Break_Lcr := Break_Lcr +  64;
  398.  
  399.    Port[ UART_LCR + Async_Base ] := Break_Lcr;
  400.  
  401.    Delay( 400 );
  402.  
  403.    Port[ UART_LCR + Async_Base ] := Old_Lcr;
  404.  
  405. END   (* Async_Send_Break *);
  406.  
  407. (*----------------------------------------------------------------------*)
  408. (*     Async_Send_String --- Send string over communications port       *)
  409. (*----------------------------------------------------------------------*)
  410.  
  411. PROCEDURE Async_Send_String( S : AnyStr );
  412.  
  413. (*----------------------------------------------------------------------*)
  414. (*                                                                      *)
  415. (*     Procedure:  Async_Send_String                                    *)
  416. (*                                                                      *)
  417. (*     Purpose:    Sends string out over communications port            *)
  418. (*                                                                      *)
  419. (*     Calling Sequence:                                                *)
  420. (*                                                                      *)
  421. (*        Async_Send_String( S : AnyStr );                              *)
  422. (*                                                                      *)
  423. (*           S --- String to send                                       *)
  424. (*                                                                      *)
  425. (*     Calls:  Async_Send                                               *)
  426. (*                                                                      *)
  427. (*----------------------------------------------------------------------*)
  428.  
  429. VAR
  430.    I : INTEGER;
  431.  
  432. BEGIN  (* Async_Send_String *)
  433.  
  434.   FOR I := 1 TO LENGTH( S ) DO
  435.      Async_Send( S[I] )
  436.  
  437. END    (* Async_Send_String *);
  438.  
  439. (*----------------------------------------------------------------------*)
  440. (*     Async_Send_String_With_Delays --- Send string with timed delays  *)
  441. (*----------------------------------------------------------------------*)
  442.  
  443. PROCEDURE Async_Send_String_With_Delays( S          : AnyStr;
  444.                                          Char_Delay : INTEGER;
  445.                                          EOS_Delay  : INTEGER  );
  446.  
  447. (*----------------------------------------------------------------------*)
  448. (*                                                                      *)
  449. (*     Procedure:  Async_Send_String_With_Delays                        *)
  450. (*                                                                      *)
  451. (*     Purpose:    Sends string out over communications port with       *)
  452. (*                 specified delays for each character and at the       *)
  453. (*                 end of the string.                                   *)
  454. (*                                                                      *)
  455. (*     Calling Sequence:                                                *)
  456. (*                                                                      *)
  457. (*        Async_Send_String_With_Delays( S          : AnyStr ;          *)
  458. (*                                       Char_Delay : INTEGER;          *)
  459. (*                                       EOS_Delay  : INTEGER );        *)
  460. (*                                                                      *)
  461. (*           S          --- String to send                              *)
  462. (*           Char_Delay --- Number of milliseconds to delay after       *)
  463. (*                          sending each character                      *)
  464. (*           EOS_Delay  --- Number of milleseconds to delay after       *)
  465. (*                          sending last character in string            *)
  466. (*                                                                      *)
  467. (*     Calls:  Async_Send                                               *)
  468. (*             Async_Send_String                                        *)
  469. (*             Length                                                   *)
  470. (*             Delay                                                    *)
  471. (*                                                                      *)
  472. (*     Remarks:                                                         *)
  473. (*                                                                      *)
  474. (*        This routine is useful when writing routines to perform       *)
  475. (*        non-protocol uploads.  Many computer systems require delays   *)
  476. (*        between receipt of characters for correct processing.  The    *)
  477. (*        delay for end-of-string usually applies when the string       *)
  478. (*        represents an entire line of a file.                          *)
  479. (*                                                                      *)
  480. (*        If delays are not required, Async_Send_String is faster.      *)
  481. (*        This routine will call Async_Send_String is no character      *)
  482. (*        delay is to be done.                                          *)
  483. (*                                                                      *)
  484. (*----------------------------------------------------------------------*)
  485.  
  486. VAR
  487.    I : INTEGER;
  488.  
  489. BEGIN  (* Async_Send_String_With_Delays *)
  490.  
  491.    IF Char_Delay <= 0 THEN
  492.       Async_Send_String( S )
  493.    ELSE
  494.       FOR I := 1 TO LENGTH( S ) DO
  495.          BEGIN
  496.             Async_Send( S[I] );
  497.             Delay( Char_Delay );
  498.          END;
  499.  
  500.    IF EOS_Delay > 0 THEN Delay( EOS_Delay );
  501.  
  502. END    (* Async_Send_String_With_Delays *);
  503.  
  504. (*----------------------------------------------------------------------*)
  505. (*      Async_Percentage_Used --- Report Percentage Buffer Filled       *)
  506. (*----------------------------------------------------------------------*)
  507.  
  508. FUNCTION Async_Percentage_Used : REAL;
  509.  
  510. (*----------------------------------------------------------------------*)
  511. (*                                                                      *)
  512. (*     Function:   Async_Percent_Used                                   *)
  513. (*                                                                      *)
  514. (*     Purpose:    Reports percentage of com buffer currently filled    *)
  515. (*                                                                      *)
  516. (*     Calling Sequence:                                                *)
  517. (*                                                                      *)
  518. (*        Percentage := Async_Percentage_Used : Real;                   *)
  519. (*                                                                      *)
  520. (*           Percentage gets how much of buffer is filled;              *)
  521. (*           value goes from 0.0 (empty) to 1.0 (totally full).         *)
  522. (*                                                                      *)
  523. (*     Calls:  None                                                     *)
  524. (*                                                                      *)
  525. (*     Remarks:                                                         *)
  526. (*                                                                      *)
  527. (*       This routine is helpful when incorporating handshaking into    *)
  528. (*       a communications program.  For example, assume that the host   *)
  529. (*       computer uses the XON/XOFF (DC1/DC3) protocol.  Then the       *)
  530. (*       PC program should issue an XOFF  to the host when the value    *)
  531. (*       returned by Async_Percentage_Used > .75 or so.  When the       *)
  532. (*       utilization percentage drops below .25 or so, the PC program   *)
  533. (*       should transmit an XON.                                        *)
  534. (*                                                                      *)
  535. (*----------------------------------------------------------------------*)
  536.  
  537. BEGIN (* Async_Percentage_Used *)
  538.  
  539.    Async_Percentage_Used := Async_Buffer_Used / ( Async_Buffer_Max + 1 );
  540.  
  541. END   (* Async_Percentage_Used *);
  542.  
  543. (*----------------------------------------------------------------------*)
  544. (*     Async_Purge_Buffer --- Purge communications input buffer         *)
  545. (*----------------------------------------------------------------------*)
  546.  
  547. PROCEDURE Async_Purge_Buffer;
  548.  
  549. (*----------------------------------------------------------------------*)
  550. (*                                                                      *)
  551. (*     Procedure:  Async_Purge_Buffer                                   *)
  552. (*                                                                      *)
  553. (*     Purpose:    Purges communications input buffer                   *)
  554. (*                                                                      *)
  555. (*     Calling Sequence:                                                *)
  556. (*                                                                      *)
  557. (*        Async_Purge_Buffer;                                           *)
  558. (*                                                                      *)
  559. (*     Calls:  Async_Receive                                            *)
  560. (*                                                                      *)
  561. (*----------------------------------------------------------------------*)
  562.  
  563. VAR
  564.    C: CHAR;
  565.    L: INTEGER;
  566.  
  567. BEGIN  (* Async_Purge_Buffer *)
  568.  
  569.    L     := 10000 DIV Async_Baud_Rate;
  570.  
  571.    IF L <= 0 THEN
  572.       L := 3;
  573.  
  574.    REPEAT
  575.       DELAY( L )
  576.    UNTIL ( NOT Async_Receive( C ) );
  577.  
  578. END    (* Async_Purge_Buffer *);
  579.  
  580. (*----------------------------------------------------------------------*)
  581. (*          Async_Buffer_Full --- Check if com buffer nearly full       *)
  582. (*----------------------------------------------------------------------*)
  583.  
  584. PROCEDURE Async_Buffer_Full;
  585.  
  586. (*----------------------------------------------------------------------*)
  587. (*                                                                      *)
  588. (*     Procedure:  Async_Buffer_Full                                    *)
  589. (*                                                                      *)
  590. (*     Purpose:    Check if buffer nearly full, issue XOFF if so.       *)
  591. (*                                                                      *)
  592. (*     Calling Sequence:                                                *)
  593. (*                                                                      *)
  594. (*        Async_Buffer_Full;                                            *)
  595. (*                                                                      *)
  596. (*     Calls:  Async_Send                                               *)
  597. (*                                                                      *)
  598. (*     Remarks:                                                         *)
  599. (*                                                                      *)
  600. (*         An XOFF if issued if the buffer is nearly full and an XOFF   *)
  601. (*         has not been previously issued.  If an XOFF was previously   *)
  602. (*         issued, and the buffer is reasonably empty,  then an XON     *)
  603. (*         is issued.                                                   *)
  604. (*                                                                      *)
  605. (*----------------------------------------------------------------------*)
  606.  
  607. BEGIN   (* Async_Buffer_Full *)
  608.  
  609.    IF ( Async_Buffer_Used * 4 ) > ( Async_Buffer_Max * 3 ) THEN
  610.       BEGIN  (* Buffer too full -- send XOFF if we already haven't *)
  611.          IF ( NOT Async_XOFF_Sent ) THEN
  612.             BEGIN
  613.                Async_Send( Async_XOFF );
  614.                Async_XOFF_Sent := TRUE;
  615.             END
  616.       END    (* Buffer too full *)
  617.    ELSE IF ( Async_Buffer_Used * 4 ) < Async_Buffer_Max THEN
  618.       BEGIN  (* Buffer reasonably empty -- send XON if needed *)
  619.          IF Async_XOFF_Sent THEN
  620.             BEGIN
  621.                Async_Send( Async_XON );
  622.                Async_XOFF_Sent := FALSE;
  623.             END;
  624.       END;
  625.  
  626. END     (* Async_Buffer_Full *);
  627.